﻿<Window
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:Local="clr-namespace:DTC.Database"
		xmlns:Converters="clr-namespace:DTC.Converters"
        xmlns:Res="clr-namespace:DTC.Resources"
        xmlns:Validations="clr-namespace:DTC.Validations"
        xmlns:DTC="clr-namespace:DTC"
        xmlns:Bindings="clr-namespace:DTC.Bindings"
	x:Class="DTC.OrderPopup"
	x:Name="Window"
	Title="Заказ"
	Width="850" Height="600" Style="{StaticResource PopupWindow}"
    Closing="Window_Closing"
    Loaded="Window_Loaded">
	<Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Brushes.xaml"/>
                <ResourceDictionary Source="../Resources/ButtonsStyles.xaml"/>
                <ResourceDictionary Source="../Resources/ComboBoxesStyles.xaml"/>
                <ResourceDictionary Source="../Resources/TextEditStyles.xaml"/>
				<ResourceDictionary Source="../Resources/ListBoxStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <DataTemplate x:Key="OrderBoxesDataTemplate">
                <Grid Margin="10,0,0,0" Height="50" VerticalAlignment="Center">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.5*"/>
                        <ColumnDefinition Width="0.5*"/>
                    </Grid.ColumnDefinitions>
                    <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="0" 
									Margin="6">
                        <StackPanel Grid.Column="0"
										Margin="4,0,4,0"
                                   			HorizontalAlignment="Center"
                                   			VerticalAlignment="Center">
                            <TextBlock Text="Название препарата:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                            <TextBlock Text="{Binding DTCBox.FullName, Mode = OneWay}"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"
											FontSize="14"/>
                        </StackPanel>
                    </Border>
                    <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="1" 
									Margin="6">
                        <StackPanel Grid.Column="1"
											Margin="4,0,4,0"
	                                   			HorizontalAlignment="Center"
	                                   			VerticalAlignment="Center">
                            <TextBlock Text="Количество"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                            <TextBlock Text="{Binding Count, Mode = OneWay}"
                                   			HorizontalAlignment="Center"
                            	       		VerticalAlignment="Center"/>
                        </StackPanel>
                    </Border>
                </Grid>
            </DataTemplate>
        </ResourceDictionary>
    </Window.Resources>

	<Grid x:Name="MainGrid" Margin="20">
		<Grid.RowDefinitions>
			<RowDefinition Height="80"/>
			<RowDefinition Height="20"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		<WrapPanel>
		<StackPanel>
			<TextBlock Text="Расчетныйе период"
						FontSize="13"/>
			<WrapPanel Margin="0,10,0,0">
				<TextBlock Text="Начиная с"
							VerticalAlignment="Bottom"/>
				<AdornerDecorator>
                                <TextBox Margin="6,0,0,0"
                                         x:Name="DateFromTB"
                                         Width="90"
                                         SnapsToDevicePixels="True"
                                         TextAlignment="Center">
                                    <Binding Path="DateFrom">
                                        <Binding.ValidationRules>
                                            <Validations:DateValidation/>
                                        </Binding.ValidationRules>
                                        <Binding.Converter>
                                            <Converters:DateTimeToDateConverter/>
                                        </Binding.Converter>
                            </Binding>
                                    <Res:WatermarkService.Watermark>
                                        <TextBlock Text="дд.мм.гггг"
                                                   FontSize="11"
                                                   FontFamily="Arial"
                                                   FontStyle="Italic"
                                                   Foreground="Black"
                                                   HorizontalAlignment="Center"/>
                                    </Res:WatermarkService.Watermark>
                                </TextBox>
                            </AdornerDecorator>
			</WrapPanel>
			<WrapPanel Margin="0,10,0,0">
				<TextBlock Text="До" VerticalAlignment="Bottom"/>
				<AdornerDecorator>
                                <TextBox Margin="6,0,0,0"
                                         x:Name="DateToTB"
                                         Width="90"
                                         SnapsToDevicePixels="True"
                                         TextAlignment="Center">
                                    <Binding Path="DateTo">
                                        <Binding.ValidationRules>
                                            <Validations:DateValidation/>
                                        </Binding.ValidationRules>
                                        <Binding.Converter>
                                            <Converters:DateTimeToDateConverter/>
                                        </Binding.Converter>
                                    </Binding>
                                    <Res:WatermarkService.Watermark>
                                        <TextBlock Text="дд.мм.гггг"
                                                   FontSize="11"
                                                   FontFamily="Arial"
                                                   FontStyle="Italic"
                                                   Foreground="Black"
                                                   HorizontalAlignment="Center"/>
                                    </Res:WatermarkService.Watermark>
                                </TextBox>
                            </AdornerDecorator>
							</WrapPanel>
		</StackPanel>
            <StackPanel>
                <Button Height="30"
                        Width="80"
                        Style="{StaticResource SearchButton}"
                        Margin="30,20,0,0" Click="Button_Click">Расчитать</Button>
                <Button Height="30"
                        Width="80"
                        Name="PrintButton"
                        Style="{StaticResource SearchButton}"
                        Margin="30,20,0,0" Click="PrintButton_Click">Расчитать</Button>
            </StackPanel>
        </WrapPanel>
		<TextBlock Text="Список препаратов"
					Grid.Row="1"
					VerticalAlignment="Center"
					HorizontalAlignment="Center"
					FontSize="15"
					FontWeight="Bold"/>
        <ListBox Name="RequieredDrugsListBox"
                 Grid.Row="2"
                 ItemContainerStyle="{StaticResource ColorListBoxItem}"
				 VerticalContentAlignment="Stretch"
				 HorizontalContentAlignment="Stretch">
            <ListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1" CornerRadius="3"
									Margin="2"
                                    Background="#44FFFFFF">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="0.5*"/>
                                        <ColumnDefinition Width="0.5*"/>
                                    </Grid.ColumnDefinitions>
                                    <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="2"
									Grid.Column="0" 
									Margin="2">
                                        <StackPanel Margin="2" Orientation="Horizontal">
                                            <TextBlock Text="Препарат:"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center" Margin="0,0,5,0"/>
                                            <TextBlock Text="{Binding Name.Name}"
                                               Grid.Column="0"
                                               VerticalAlignment="Center"
                                               HorizontalAlignment="Center"
											   Foreground="#FF2C2C2C"
                                                       FontSize="13"
                                               FontWeight="Bold"/>
                                        </StackPanel>
                                    </Border>
                                    <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="2"
									Grid.Column="1" 
									Margin="2">
                                        <StackPanel Margin="2" Orientation="Horizontal">
                                            <TextBlock Text="Всего:"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Top"
                                                       Margin="0,0,15,0"/>
                                            <ListBox Loaded="ListBox_Loaded" Grid.Column="1"
                                                     Background="Transparent" BorderThickness="0">
                                                <ListBox.ItemContainerStyle>
                                                    <Style TargetType="{x:Type ListBoxItem}">
                                                        <Setter Property="Template">
                                                            <Setter.Value>
                                                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                                    <Grid Name="Ground">
                                                                        <ContentPresenter SnapsToDevicePixels="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"/>
                                                                    </Grid>
                                                                </ControlTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Style>
                                                </ListBox.ItemContainerStyle>
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <Grid>
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="0.7*"/>
                                                                <ColumnDefinition Width="0.3*"/>
                                                            </Grid.ColumnDefinitions>
                                                            <StackPanel Grid.Column="0" Orientation="Horizontal">
                                                                <TextBlock Text="{Binding DTCBox.FormatedDrug}"/>
                                                                <TextBlock Text=" - "/>
                                                            </StackPanel>
                                                            <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Stretch">
                                                                <TextBlock Text="{Binding Count}" Width="Auto" />
                                                                <TextBlock Text="шт." Margin="5,0,0,0"/>
                                                            </StackPanel>
                                                        </Grid>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </StackPanel>
                                    </Border>
                                </Grid>
                            </Border>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListBox.GroupStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="10,0,0,0" MinHeight="70" VerticalAlignment="Center">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.33*"/>
                            <ColumnDefinition Width="0.33*"/>
                            <ColumnDefinition Width="0.33*"/>
                        </Grid.ColumnDefinitions>
                        <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="0" 
									Margin="6">
                            <StackPanel Grid.Column="0"
										Margin="4,0,4,0"
                                   			HorizontalAlignment="Center"
                                   			VerticalAlignment="Center">
                                <TextBlock Text="Пациент:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                                <TextBlock Text="{Binding Path=DTCDrugPrescription.DTCPatient.FullName, Mode=OneWay}"
                                           HorizontalAlignment="Center"/>
                            </StackPanel>
                        </Border>
                        <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="1" 
									Margin="6">
                            <StackPanel Grid.Column="0"
										Margin="4,0,4,0"
                                   			HorizontalAlignment="Center"
                                   			VerticalAlignment="Center">
                                <TextBlock Text="Препарат:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                                <TextBlock Text="{Binding Path=DTCDrugPrescription.DTCDrugUnit.DTCDrug.Name, Mode=OneWay}"
                                           HorizontalAlignment="Center"/>
                            </StackPanel>
                        </Border>
                        <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="2" 
									Margin="6">
                            <StackPanel Grid.Column="0"
										Margin="4,0,4,0"
                                   			HorizontalAlignment="Center"
                                   			VerticalAlignment="Center">
                                <TextBlock Text="Упаковки:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                                <ListBox ItemsSource="{Binding DTCPatientOrderedBoxes}" DisplayMemberPath="BoxCount"
                                         Background="Transparent" BorderThickness="0">
                                    <ListBox.ItemContainerStyle>
                                        <Style TargetType="{x:Type ListBoxItem}">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                        <Grid Name="Ground">
                                                            <ContentPresenter SnapsToDevicePixels="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"/>
                                                        </Grid>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </ListBox.ItemContainerStyle>
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="0.7*"/>
                                                    <ColumnDefinition Width="0.3*"/>
                                                </Grid.ColumnDefinitions>
                                                <StackPanel Grid.Column="0" Orientation="Horizontal">
                                                    <TextBlock Text="{Binding DTCBox.FormatedDrug}"/>
                                                    <TextBlock Text=" - "/>
                                                </StackPanel>
                                                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Stretch">
                                                    <TextBox Text="{Binding Count}" Width="Auto" />
                                                    <TextBlock Text="шт." Margin="5,0,0,0"/>
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </StackPanel>
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Grid.Column="1" Grid.Row="2"
					VerticalAlignment="Center" Margin="5,0,5,0"/>
	</Grid>
</Window>